package com.example.module_course.pages

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.module_course.common.FixedAndAdaptive
import com.example.module_course.common.StatusBarColor
import com.example.module_course.common.TopTitleBar
import com.example.module_course.utils.openVideo
import com.example.module_course.utils.videoCourseEntityList
import com.fenghuajueli.libbasecoreui.baseswitch.PublicFunction
import com.fenghuajueli.module_user.ui.widget.noRippleClickable

//@Preview
@Composable
fun MoreCourseScreen(courseType: String = "基础课",onBackClick: () -> Unit) {
    StatusBarColor(color = Color.White)
    Column(modifier = Modifier.background(Color.White)) {
        TopTitleBar(courseType) {
            onBackClick()
        }

        LazyVerticalGrid(
            columns = FixedAndAdaptive(2, 162.dp),
            horizontalArrangement = Arrangement.spacedBy(12.dp),
            verticalArrangement = Arrangement.spacedBy(20.dp),
            contentPadding = PaddingValues(20.dp)
        ) {
            items(videoCourseEntityList.filter { it.category.contains(courseType) }) {
                Column(modifier = Modifier.noRippleClickable {
                    if (PublicFunction.checkCanUsedByPosition(2, true)) {
                        it.url.openVideo()
                    }
                }) {
                    Image(painter = painterResource(id = it.imgRes), contentDescription = null)
                    Text(
                        text = it.name,
                        style = TextStyle(
                            color = Color(0xFF333333),
                            fontSize = 12.sp,
                            fontWeight = FontWeight.Medium
                        ),
                        maxLines = 1,
                        overflow = TextOverflow.Ellipsis,
                        modifier = Modifier.padding(top = 8.dp)
                    )

                    Row(
                        horizontalArrangement = Arrangement.spacedBy(16.dp),
                        verticalAlignment = Alignment.CenterVertically,
                        modifier = Modifier.padding(top = 5.dp)
                    ) {
                        Text(
                            text = "${(3000..8000).random()}人浏览", style = TextStyle(
                                color = Color(0xFF999999),
                                fontSize = 10.sp,
                                fontWeight = FontWeight.Normal
                            )
                        )

                        Text(
                            text = "${(3000..8000).random()}人收藏", style = TextStyle(
                                color = Color(0xFF999999),
                                fontSize = 10.sp,
                                fontWeight = FontWeight.Normal
                            )
                        )
                    }
                }
            }
        }
    }
}